using System.Collections.Generic;
using System;

namespace PropertySystem
{
    [Serializable]
    public class ValueModifier
    {
        private DataRegistry<float> _baseAdd;
        private DataRegistry<float> _percentage;
        private DataRegistry<float> _addition;
        private float _value;
        public float Value { get => _value; private set => _value = value; }

        public ValueModifier()
        {
            _baseAdd = new DataRegistry<float>();
            _percentage = new DataRegistry<float>();
            _addition = new DataRegistry<float>();
            Value = 0;
        }

        public void Register(string key, float value, ModifierType modifierType, params RegistryType[] registryTags)
        {
            switch (modifierType)
            {
                case ModifierType.BaseAdd:
                    if (_baseAdd.ContainsKey(key)) return;
                    _baseAdd.Register(key, value, registryTags);
                    break;
                case ModifierType.Percentage:
                    if (_percentage.ContainsKey(key)) return;
                    _percentage.Register(key, value, registryTags);
                    break;
                case ModifierType.Addition:
                    if (_addition.ContainsKey(key)) return;
                    _addition.Register(key, value, registryTags);
                    break;
                default:
                    break;
            }
            RefreshValue();
        }

        public void Unregister(string key)
        {
            if (_baseAdd.ContainsKey(key)) _baseAdd.Unregister(key);
            if (_percentage.ContainsKey(key)) _percentage.Unregister(key);
            if (_addition.ContainsKey(key)) _addition.Unregister(key);
            RefreshValue();
        }

        public bool CheckKey(string key)
        {
            return _baseAdd.ContainsKey(key) || _percentage.ContainsKey(key) || _addition.ContainsKey(key);
        }

        public void RefreshValue()
        {
            //float result = 0;
            //foreach (var item in _baseAdd.Values) { result += item; }
            //float percent = 100f;
            //foreach (var item in _percentage.Values) { percent += item; }
            //result = percent / 100f * result;
            //foreach (var item in _addition.Values) { result += item; }
            //////Value = result;
        }
    }
}

